<template>
  <div class="recommend">
    <div class="music-list" >
    <div class="top">
      <div class="left">
        <span class="back" @click="back"></span>
        <span class="play-list">歌单</span>
      </div>
      <div class="right">
        <span class="search"></span>
        <span class="more"></span>
      </div>
    </div>
      <img class="bgImg" :src="songList.coverImgUrl" >
      <div class="bg" >
        <div class="pic">
          <img :src="songList.coverImgUrl" />
          <span class="count">{{songList.playCount | formatNum}}</span>
          <span class="song-list">歌单</span>
        </div>
        <div class="music-text">
          <span> {{songList.name}} </span>
        </div>
      </div>
      <div class="songlist">
        <span>歌单列表</span>
      </div>
    </div>
    
    <ul>
      <DailyHot v-for="(item,index) in newSongList" :item="item" :num="index" :key="index"></DailyHot>
    </ul>
    <div class="comments">
      <div class="title"><span>最新评论({{commentTotal}})</span></div>
      <Comments  v-for="(item,index) in songComments" :item="item" :num="index" :key="index"></Comments>
    </div>
  </div>
</template>

<script>
import Comments from '../components/Comments.vue';
import DailyHot from "../components/DailyHot";
export default {
  name: "Recommend",
  components: {
    DailyHot,
    Comments,
  },
  data() {
    return {
      musicList: [],
      songList:[],
      newSongList: [],
      songComments:[],
      commentTotal:0,
      musicId:''
    };
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      let musicids = [];
      vm.$http
        .get(`/playlist/detail?id=${to.params.musicId}`)
        .then((data) => {
          musicids=data.data.playlist.trackIds.slice(0,20);
          vm.songList = data.data.playlist;
        }).then(() => {
          for (let v of musicids) {
            vm.$http.get("song/detail?ids=" + v.id).then((data) => {
              vm.newSongList.push({
                name: data.data.songs[0].name,
                id: data.data.songs[0].id,
                song: {
                  privilege: {
                    maxbr: data.data.privileges[0].maxbr,
                  },
                  artists: data.data.songs[0].ar,
                },
              });
            });
          }
        }).then(() => {
          vm.$http.get('/comment/playlist?id='+to.params.musicId).then((data)=>{
            vm.commentTotal = data.data.total;
            vm.songComments = data.data.comments;
          })
        }).catch((error) => {
          console.log(error);
        });
    });
  },
  methods: {
    back() {
      this.$router.back();
    },
  },
  filters: {
    formatNum(value) {
      return (value / 10000).toFixed(1) + "万";
    },
  },
  
};
</script>
<style lang="less" scoped>
.music-list {
  .top {
    width: 100%;
    height: 40px;
    position: relative;
    display: flex;
    justify-content: space-between;
    color: white;
    .left {
      line-height: 40px;
      .back {
        display: inline-block;
        width: 30px;
        height: 30px;
        margin: 0px 10px;
        background: url(../assets/fanhui.png) no-repeat;
        background-size: 30px;
        vertical-align: middle;
      }
      .play-list {
        display: inline-block;
      }
    }
    .right {
      .search {
        display: inline-block;
        width: 20px;
        margin-top: 10px;
        height: 20px;
        background: url(../assets/sousuo.png) no-repeat;
        background-size: 20px;
      }
      .more {
        display: inline-block;
        margin: 0 5px;
        width: 20px;
        height: 20px;
        background: url(../assets/ziyuan.png) no-repeat;
        background-size: 20px;
      }
    }
  }
  position: relative;
  overflow: hidden;
  // padding-top: 40px;
  .bgImg{
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
    width: 100%;
    background-color: rgba(0,0,0,.25);
    filter: blur(10px);
  }
  .bg {
    display: flex;
    width: 100%;
    justify-content: space-around;
    padding: 10px;
    box-sizing: border-box;
    .pic {
      // flex: auto;
      position: relative;
      width: 25%;
      border-radius: 10px;  
      overflow: hidden;
      img {
        display: block;
        width: 100%;
      }
      span.count {
        position: absolute;
        top: 0;
        right: 0;
        padding:  3px;
        font-size: 10px;
        color: white;
        text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.5);
      }
      span.song-list{
        position: absolute;
        top: 10px;
        left: 0;
        width: 40px;
        height: 17px;
        font-size: 12px;
        color: white;
        background-color: #BD3738;
        border-radius: 0 17px 17px 0;
      }
    }
    .music-text {
      flex: 1;
      margin-left: 5px;
      text-align: left;
      color: #fff;
      span {
        padding-left: 10px;
      }
    }
  }
  .songlist{
    width: 100%;
    height: 20px;
    background-color: #EEEFF0;
    text-align: left;
    span{
      padding-left: 5px;
      font-size: 14px;
      line-height: 20px;
    }
  }
}
.comments{
  width: 100%;
  .title{
    width: 100%;
    height: 20px;
    line-height: 20px;
    text-align: left;
    background-color: #F2F2F2;
    span{
      font-size: 14px;
      padding-left: 5px;
    }
  }
}
</style>
